home *** CD-ROM | disk | FTP | other *** search
- // ==================================================
- // CDateEditField.cp
- // Copyright (C) 1996 Mizutori Tetsuya, July 4 1996.
- // ==================================================
- // All documents are pretty-printed in Geneva 10-point font.
-
- #include <LDialogBox.h>
- #include <UDrawingState.h>
-
- #include "touchMeConstants.h"
- #include "CDateEditField.h"
- #include "UDateTime.h"
-
-
- // --------------------------------------------------
- // ・ CreateDateEditFieldStream [static]
- // --------------------------------------------------
-
- CDateEditField *
- CDateEditField::CreateDateEditFieldStream(
- LStream *inStream )
- {
- return new CDateEditField( inStream );
- }
-
-
- // --------------------------------------------------
- // ・ CDateEditField
- // --------------------------------------------------
-
- CDateEditField::CDateEditField()
- {
- mHasChanged = false;
- }
-
-
- // --------------------------------------------------
- // ・ CDateEditField(const CDateEditField&)
- // --------------------------------------------------
-
- CDateEditField::CDateEditField(
- const CDateEditField &inOriginal )
- : LEditField( inOriginal ), LListener( inOriginal ), LBroadcaster( inOriginal )
- {
- mHasChanged = false;
- }
-
-
- // --------------------------------------------------
- // ・ CDateEditField(SPaneInfo&, ... , inHasWordWrap, ...)
- // --------------------------------------------------
-
- CDateEditField::CDateEditField(
- const SPaneInfo &inPaneInfo,
- Str255 inString,
- ResIDT inTextTraitsID,
- Int16 inMaxChars,
- Boolean inHasBox,
- Boolean inHasWordWrap,
- KeyFilterFunc inKeyFilter,
- LCommander *inSuper)
- : LEditField( inPaneInfo, inString, inTextTraitsID, inMaxChars,
- inHasBox, inHasWordWrap, inKeyFilter, inSuper)
- {
- mHasChanged = false;
- }
-
-
- // --------------------------------------------------
- // ・ CDateEditField(SPaneInfo&, ... , inAttributes, ...)
- // --------------------------------------------------
-
- CDateEditField::CDateEditField(
- const SPaneInfo &inPaneInfo,
- Str255 inString,
- ResIDT inTextTraitsID,
- Int16 inMaxChars,
- Uint8 inAttributes,
- KeyFilterFunc inKeyFilter,
- LCommander *inSuper)
- : LEditField( inPaneInfo, inString, inTextTraitsID, inMaxChars,
- inAttributes, inKeyFilter, inSuper)
- {
- mHasChanged = false;
- }
-
-
- // --------------------------------------------------
- // ・ CDateEditField(LStream*)
- // --------------------------------------------------
-
- CDateEditField::CDateEditField(
- LStream *inStream )
- : LEditField( inStream )
- {
- mHasChanged = false;
- }
-
-
- // --------------------------------------------------
- // ・ ~CDateEditField
- // --------------------------------------------------
-
- CDateEditField::~CDateEditField()
- {
- }
-
-
- // --------------------------------------------------
- // ・ ListenToMessage
- // --------------------------------------------------
- void
- CDateEditField::ListenToMessage(
- MessageT inMessage,
- void *ioParam )
- {
- #pragma unused( inMessage, ioParam )
-
- //PaneIDT thisPaneID = GetPaneID();
- //Int32 thisUserCon = GetUserCon();
-
- // Do not refresh the EditField if click is still in this EditField.
- //if ( inMessage == thisUserCon ) return;
-
- //RefreshEditField();
- }
-
-
- // --------------------------------------------------
- // ・ UserChangedText
- // --------------------------------------------------
-
- void
- CDateEditField::UserChangedText( void )
- {
- LEditField::UserChangedText();
-
- mHasChanged = true;
- }
-
-
- // --------------------------------------------------
- // ・ ClickSelf
- // --------------------------------------------------
-
- void
- CDateEditField::ClickSelf(
- const SMouseDownEvent & inMouseDown )
- {
- LEditField::ClickSelf( inMouseDown );
-
- // Int32 thisUserCon = GetUserCon();
- // BroadcastMessage( (MessageT) thisUserCon, nil );
- }
-
-
- // --------------------------------------------------
- // ・ BeTarget
- // --------------------------------------------------
-
- void
- CDateEditField::BeTarget( void )
- {
- LEditField::BeTarget();
-
- // Int32 thisUserCon = GetUserCon();
- // BroadcastMessage( (MessageT) thisUserCon, nil );
- }
-
-
- // --------------------------------------------------
- // ・ DontBeTarget
- // --------------------------------------------------
-
- void
- CDateEditField::DontBeTarget( void )
- {
- LEditField::DontBeTarget();
-
- // Int32 thisUserCon = GetUserCon();
- // BroadcastMessage( (MessageT) thisUserCon, nil );
-
- long theSelStart, theSelEnd;
- GetSelect( theSelStart, theSelEnd );
- RefreshEditField();
- SetSelect( theSelStart, theSelEnd );
- }
-
-
- // ==================================================
- // Common functions
- // ==================================================
-
- // --------------------------------------------------
- // ・ GetTEActive
- // --------------------------------------------------
-
- Boolean
- CDateEditField::GetTEActive( void )
- {
- TEHandle theTextEditH = GetMacTEH();
-
- return (Boolean) ( (**theTextEditH).active != 0 );
- }
-
-
- // --------------------------------------------------
- // ・ SetTEActive
- // --------------------------------------------------
-
- void
- CDateEditField::SetTEActive(
- const Boolean inStatus )
- {
- TEHandle theTextEditH = GetMacTEH();
-
- if ( inStatus ) ::TEActivate( theTextEditH );
- else ::TEDeactivate( theTextEditH );
-
- ::TEIdle( theTextEditH );
- }
-
-
- // --------------------------------------------------
- // ・ GetSelect
- // --------------------------------------------------
-
- void
- CDateEditField::GetSelect(
- long & outSelStart,
- long & outSelEnd )
- {
- TEHandle theTextEditH = GetMacTEH();
-
- outSelStart = (**theTextEditH).selStart;
- outSelEnd = (**theTextEditH).selEnd;
- }
-
-
- // --------------------------------------------------
- // ・ SetSelect
- // --------------------------------------------------
-
- void
- CDateEditField::SetSelect(
- const long inSelStart,
- const long inSelEnd )
- {
- TEHandle theTextEditH = GetMacTEH();
- ::TESetSelect( inSelStart, inSelEnd, theTextEditH );
- }
-
-
- // --------------------------------------------------
- // ・ GetText
- // --------------------------------------------------
-
- void
- CDateEditField::GetText(
- Str255 outString )
- {
- TEHandle theHandle = GetMacTEH();
-
- outString[0] = (**theHandle).teLength;
- ::BlockMoveData( *((**theHandle).hText), &outString[1], outString[0] );
- }
-
- // --------------------------------------------------
- // ・ SetText
- // --------------------------------------------------
-
- void
- CDateEditField::SetText(
- const Str255 inString )
- {
- TEHandle theHandle = GetMacTEH();
-
- ::TESetText( &inString[1], inString[0], theHandle );
-
- Refresh();
-
- mHasChanged = true;
- }
-
-
- // --------------------------------------------------
- // ・ SetTextAndRefresh
- // --------------------------------------------------
-
- void
- CDateEditField::SetTextAndRefresh(
- const Str255 inString )
- {
- SetText( inString );
- RefreshEditField();
- }
-
-
- // --------------------------------------------------
- // ・ SetDateTime
- // --------------------------------------------------
-
- void
- CDateEditField::SetDateTime(
- const unsigned long inDateTimeSeconds )
- {
- PaneIDT thisPaneID = GetPaneID();
- Str255 theDateString, theTimeString;
-
- UDateTime::SecondsToDateTimeString( inDateTimeSeconds, theDateString, theTimeString );
-
- switch ( thisPaneID ) {
- case kTmeD_CrTextEditDate:
- case kTmeD_MdTextEditDate:
- SetText( theDateString );
- break;
-
- case kTmeD_CrTextEditTime:
- case kTmeD_MdTextEditTime:
- SetText( theTimeString );
- break;
- }
-
- // Do not need refresh this EditField.
- mHasChanged = false;
- }
-
-
- // --------------------------------------------------
- // ・ RefreshEditField
- // --------------------------------------------------
-
- void
- CDateEditField::RefreshEditField( void )
- {
- PaneIDT thisPaneID = GetPaneID();
-
- // Do not refresh the EditField if text has not been changed.
- if ( ! mHasChanged ) return;
-
- // Refresh the EditField, and then reset the flag 'mHasChanged'.
- Str63 theStrDate="¥p1", theStrTime="¥p0";
- unsigned long theSeconds;
-
- switch ( thisPaneID ) {
- case kTmeD_CrTextEditDate:
- case kTmeD_MdTextEditDate:
- {
- GetText( theStrDate );
- UDateTime::DateTimeStringToSeconds(theStrDate,theStrTime,theSeconds);
- UDateTime::SecondsToDateTimeString(theSeconds,theStrDate,theStrTime);
- SetText( theStrDate );
- }
- break;
-
- case kTmeD_CrTextEditTime:
- case kTmeD_MdTextEditTime:
- {
- GetText( theStrTime );
- UDateTime::DateTimeStringToSeconds(theStrDate,theStrTime,theSeconds);
- UDateTime::SecondsToDateTimeString(theSeconds,theStrDate,theStrTime);
- SetText( theStrTime );
- }
- break;
- }
-
- mHasChanged = false;
- }
-
- // end of program
-